package com.itxx.allTools.homeWork.bigDecimal;

import java.math.BigDecimal;
import java.util.Arrays;

//	double[] arr = {0.1,0.2,2.1,3.2,5.56,7.21};
public class Test1 {
    public static void main(String[] args) {
        double[] arr = {0.1,0.2,2.1,3.2,5.56,7.21};
        //字符串拼接
        String s="";
        for (int i = 0; i < arr.length; i++) {
            s+=arr[i]+" ";
        }
        //用" "条件切割字符串为 String数组
        String[] split = s.split(" ");
        System.out.println(s);
       getAvg(split);
    }
   private static void getAvg(String[] split) {
        BigDecimal sum = BigDecimal.ZERO;
        for (int i = 0; i < split.length; i++) {
            BigDecimal bigDecimal = new BigDecimal(split[i]);
            sum = bigDecimal.add(sum);
        }
        System.out.println(sum);
        BigDecimal avg = sum.divide(new BigDecimal(String.valueOf(split.length)), 2, BigDecimal.ROUND_UP);
        System.out.println(avg);
    }
}

